Namespace PL.MESSDK
    Public Class LotStock_PL
        Inherits PLBase
        Implements IPLProcess

        'Reflection requirement for factorization
        Public Sub New()
            MyBase.New()
        End Sub

        Public Sub New(ByVal queryName As String)
            MyBase.New(queryName)
        End Sub

        Public Overrides Function Delete() As Boolean
            'Throw New NotImplementedException("Delete To Come...")
            Return False
        End Function

        Public Overrides Function Validate() As Boolean
            'Throw New NotImplementedException("Validate To Come...")
            Return True
        End Function

        Public Overrides Sub ValidateRow(row As DataRow)
            row.ClearErrors()

            If IsDBNull(row("LotID_FK")) Then
                row.SetColumnError("LotID_FK", "Mandatory")
            End If
            If IsDBNull(row("WhBinID_FK")) Then
                row.SetColumnError("WhBinID_FK", "Mandatory")
            End If
            If IsDBNull(row("QtyAvail")) Then
                row.SetColumnError("QtyAvail", "Mandatory")
            End If

            If IsDBNull(row("QtyOnHand")) Then
                row.SetColumnError("QtyOnHand", "Mandatory")
            End If

            If IsDBNull(row("QtyRequested")) Then
                row.SetColumnError("QtyRequested", "Mandatory")
            End If

            If IsDBNull(row("QtyReserved")) Then
                row.SetColumnError("QtyReserved", "Mandatory")
            End If

            If IsDBNull(row("QtyWIP")) Then
                row.SetColumnError("QtyWIP", "Mandatory")
            End If

            If IsDBNull(row("QtyQI")) Then
                row.SetColumnError("QtyQI", "Mandatory")
            End If

            If IsDBNull(row("QtyObsolete")) Then
                row.SetColumnError("QtyObsolete", "Mandatory")
            End If

            If IsDBNull(row("StorageUnitId_FK")) Then
                row.SetColumnError("StorageUnitId_FK", "Mandatory")
            End If

            'If IsDBNull(row("LUpd_LotTranId_FK")) Then
            '    row.SetColumnError("LUpd_LotTranId_FK", "Mandatory")
            'End If
            '
            If row.HasErrors Then
                row.RowError = "Please check your columns, a validation error occur"
            End If
        End Sub

        ''' <summary>
        ''' Retourne un record de LotStock Par lot
        ''' </summary>
        ''' <param name="lotID"></param>
        ''' <param name="sectionID"></param>
        ''' <returns>Return a DataRow when found, Default = Noting</returns>
        ''' <remarks>Use Shared Function From Lot_PL</remarks>
        Public Shared Function GetLotStockByLotAndSection(ByVal lotID As Guid, ByVal sectionID As Guid) As DataRow
            Return SystemBoxSDK.PL.MESSDK.Lot_PL.GetLotSectionByID(lotID, sectionID)
        End Function

        Public Function BatchRecords(dataRow() As System.Data.DataRow) As Boolean Implements IPLProcess.BatchRecords
            Return True
        End Function

        Public Function CurrentRecord(dataRow As System.Data.DataRow) As Boolean Implements IPLProcess.CurrentRecord
            Return True
        End Function

        Public Function NewRecord(dataRow As System.Data.DataRow) As Boolean Implements IPLProcess.NewRecord
            dataRow("LotStockID") = Guid.NewGuid()
            dataRow("QtyAvail") = 0
            dataRow("QtyOnHand") = 0
            dataRow("QtyReserved") = 0
            dataRow("QtyRequested") = 0
            dataRow("QtyWIP") = 0
            dataRow("QtyQI") = 0
            dataRow("QtyObsolete") = 0
            Return True
        End Function
    End Class
End Namespace
